<?php
/*
 module:		轮播图管理
 create_time:	2022-03-08 10:56:46
 author:	陕西格创
 contact:		
*/

namespace app\api\controller;

use app\api\service\ZhBannerService;
use app\api\model\ZhBanner as ZhBannerModel;
use think\exception\ValidateException;
use think\facade\Db;
use think\facade\Log;
use app\backend\model\SysSite as SysSiteModel;


class ZhBanner extends Common
{
    
    
    /**
     * @api             {get} /ZhBanner/index 01、首页数据列表
     * @apiGroup        ZhBanner
     * @apiVersion      1.0.0
     * @apiDescription  首页数据列表
     * @apiParam (输入参数：) {int}            [limit] 每页数据条数（默认20）
     * @apiParam (输入参数：) {int}            [page] 当前页码
     * @apiParam (输入参数：) {int}            [type] 轮播图类型 首页|1|success,启动页|0|warning
     * @apiParam (输入参数：) {string}        [createtime_start] 创建时间开始
     * @apiParam (输入参数：) {string}        [createtime_end] 创建时间结束
     * @apiParam (失败返回参数：) {object}        array 返回结果集
     * @apiParam (失败返回参数：) {string}        array.status 返回错误码 201
     * @apiParam (失败返回参数：) {string}        array.msg 返回错误消息
     * @apiParam (成功返回参数：) {string}        array 返回结果集
     * @apiParam (成功返回参数：) {string}        array.status 返回错误码 200
     * @apiParam (成功返回参数：) {string}        array.data 返回数据
     * @apiParam (成功返回参数：) {string}        array.data.list 返回数据列表
     * @apiParam (成功返回参数：) {string}        array.data.count 返回数据总数
     * @apiSuccessExample {json} 01 成功示例
     * {"status":"200","data":""}
     * @apiErrorExample {json} 02 失败示例
     * {"status":" 201","msg":"查询失败"}
     */
    function index()
    {
        $wxapp_id = $this->request->get('wxapp_id');
        $type     = $this->request->get('type', '', 'serach_in');
        if (!$wxapp_id) {
            return $this->ajaxReturn($this->errorCode, '缺少平台参数');
        }
        $wxSetting = SysSiteModel::where('wxapp_id', $wxapp_id)->find();
        if (!$wxSetting) {
            return $this->ajaxReturn($this->errorCode, '平台参数未配置');
        }
        $limit = $this->request->get('limit', 20, 'intval');
        $page  = $this->request->get('page', 1, 'intval');
        
        $where = [];
        
        if ($type || $type == 0) {
            $where['type'] = $type;
        }
        $where['wxapp_id'] = $wxapp_id;
        $field             = '*';
        $orderby           = 'banner_id desc';
        
        $res = ZhBannerService::indexList(formatWhere($where), $field, $orderby, $limit, $page);
        //		foreach ($res['list'] as &$v){
        //		    $v['image'] = $this->request->domain() . $v['image'];
        //        }
        unset($v);
        return $this->ajaxReturn($this->successCode, '返回成功', htmlOutList($res));
    }
    
    
    
    
}

